import {createAction, createThunkAction} from "../../lib/redux-utils";
import {get, postForm, postJson} from "../../lib/http";
import {getPrincipal} from "../../lib/identity";

const principal = getPrincipal();
export const showCreate = createAction("CLIENT.SHOW_CREATE");
export const hideCreate = createAction("CLIENT.HIDE_CREATE");
export const showModify = createAction("CLIENT.SHOW_MODIFY");
export const hideModify = createAction("CLIENT.HIDE_MODIFY");
export const showCreateRate = createAction("CLIENT.SHOW_CREATE_RATE");
export const hideCreateRate = createAction("CLIENT.HIDE_CREATE_RATE");
export const showCreateLinePrice = createAction("CLIENT.SHOW_CREATE_LINE_PRICE");
export const hideCreateLinePrice = createAction("CLIENT.HIDE_CREATE_LINE_PRICE");
export const showUpdateRate = createAction("CLIENT.SHOW_UPDATE_RATE");
export const hideUpdateRate = createAction("CLIENT.HIDE_UPDATE_RATE");
export const showUpdateLinePrice = createAction("CLIENT.SHOW_UPDATE_LINE_PRICE");
export const hideUpdateLinePrice = createAction("CLIENT.HIDE_UPDATE_LINE_PRICE");
export const updateClientModel = createAction("CLIENT.UPDATE_CLIENT_MODEL");
export const updateFeeList = createAction("CLIENT.UPDATE_FEE_LIST");
export const updateBaoGuanFee = createAction("CLIENT.UPDATE_BAOGUAN_FEE");
export const updateVehicleFees = createAction("CLIENT.VEHICLE_FEE");
export const updateLinePriceModel = createAction("CLIENT.UPDATE_LINE_PRICE_MODEL");
export const updateLinePriceInCreateModel = createAction("CLIENT.UPDATE_LINE_PRICE_IN_CREATE_MODEL");
export const addLinePriceInCreateModel = createAction("CLIENT.ADD_LINE_PRICE_IN_CREATE_MODEL");

export const getById = createThunkAction('CLIENT.GET', params =>
    get('/client/' + params)
);
export const query = createThunkAction("CLIENT.QUERY", params =>
    postJson("/client/query", params)
);
export const modify = createThunkAction("CLIENT.MODIFY", params =>
    postJson("/client/modify", params)
);
export const getCurrencyList = createThunkAction("CLIENT.GET_CURRENCY", () =>
    get("/rate/currency")
);
export const getFeeList = createThunkAction("CLIENT.GET_FEE_LIST", () =>
    get("/feeItem/all")
);
export const createLinePrice = createThunkAction("CLIENT.CREATE_LINE_PRICE", params =>
    postJson("/linePrice/create", params)
);
export const queryLinePrice = createThunkAction("CLIENT.QUERY_LINE_PRICE", params =>
    postJson("/linePrice/query", params)
);
export const updateLinePrice = createThunkAction("CLIENT.UPDATE_LINE_PRICE", params =>
    postJson("/linePrice/modify", params)
);
export const getBusinessList = createThunkAction("CLIENT.GET_BUSINESS", () =>
    postJson("/bsCode/getAll", {})
);
export const deleteLinePrice = createThunkAction("CLIENT.DELETE_LINE_PRICE", params =>
    get("/linePrice/del/" + params + "/" + getPrincipal().id)
);
export const create = createThunkAction("CLIENT.CREATE", params =>
    postJson("/client/create", params)
);
export const del = createThunkAction("", params =>
    get("/client/del/" + params + "/" + principal.id)
);
export const getCommonRate = createThunkAction("CLIENT.GET_COMMON_RATE", params =>
    get("/rate/getCommon")
);
export const getTransportType = createThunkAction("CLIENT.GET_TRANSPORT_TYPE", params =>
    get("/transportType/all")
);
export const findFeesByClientId = createThunkAction("CLIENT.UPDATE_CLIENT_FEE", params =>
    get("/client/findFeesByClientId/" + params)
);
export const getVehicleFeesByClientId = createThunkAction("CLIENT.VEHICLE_FEE_QUERY", params =>
    postJson("/client/vehicleFees", params)
);
export const getVehicleFeesByCarrierId = createThunkAction("CLIENT.VEHICLE_FEE_QUERY", params =>
    postJson("/carrier/vehicleFees", params)
);
export const lineImport = createThunkAction("CLIENT.LINE_IMPORT", params =>
    postForm("/linePrice/lineImport/" + params.belongId + "/" + params.opId + "/" + params.organizationId, params)
);
export const importClient = createThunkAction("CLIENT.IMPORT", params =>
    postForm("/client/import/" + params.opId, params)
);

export const importVehicle = createThunkAction("CLIENT.IMPORT_VEHICLE", params =>
    postForm("/client/importVehicle/" + params.belongId, params)
);
export const lineImportInCreateModal = createThunkAction("CLIENT.IMPORT_LINE_IN_CREATE_MODAL", params =>
    postForm("/linePrice/importLineInCreateModal", params)
);
export const delVehiclePrice = createThunkAction("CLIENT.DEL_VEHICLE_PRICE", params =>
    get("/client/delVehiclePrice/" + params)
);

